<?php

namespace app\api\controller\web\frontend;

use app\common\controller\Api;
use think\facade\Db;

/**
 * 高价值服务
 */
class Highserver extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 高价值服务列表
     */
    public function list()
    {
        // 分类
        $type = input('type') ?? 0;
        $address = input('address') ?? '';
        $keywords = input('keywords') ?? '';
        $where = [];
        if ($type) {
            $where[] = ['type', '=', $type];
        }
        if ($address) {
            $where[] = ['address', 'like', '%'.$address.'%'];
        }
        if ($keywords) {
            $where[] = ['title|address|phone', 'like', '%'.$keywords.'%'];
        }

        $where[] = ['is_showswitch','=',1];
        $where[] = ['deletetime','=',null];

        // 分页
        $page = !empty(input('page')) ? input('page') : 1;
        $page_size = !empty(input('page_size')) ? input('page_size') : 10;
        if ($page < 1) {
            $page = 1;
        }
        $start = ($page - 1) * $page_size;

        $arr = Db::name('web_label')->where('id','>',0)->select()->toArray();
        $type_arr = array_column($arr, 'name','id');
        // 专利保险
        $list = Db::name('web_highserver')->field('id, title, weigh, address, phone,type')->where($where)->order('createtime desc')->limit($start, $page_size)->select()->toArray();
        foreach ($list as $k => $v) {
            $list[$k]['type_name'] = $type_arr[$v['type']];
            // 加一个type标记为consult_type的id
            $list[$k]['type_id'] = Db::name('web_consult_type')->where('type',1)->value('id');
        }
        

        $count = Db::name('web_highserver')->where($where)->count();
        
        $data = [
            'page'=>$page,
            'page_size'=>$page_size,
            'count'=>$count,
            'list'=>$list,
        ]; 

        $this->success('success',$data);
    }




}
